// 引入请求所需要的函数
import { reqDetailData } from '@/api'

const state = {
  goodDetailInfo: {}
}

const actions = {
  // 在此处发送请求获取请求得到的数据
  async getDetailData({ commit }, id) {
    const result = await reqDetailData(id);
    console.log("商品详情业数据:", result);
    if (result.code === 200) {
      commit('GET_DETAIL_DATA', result.data);
    } else {
      console.log(result.message);
    }
  }
}

const mutations = {
  GET_DETAIL_DATA(state, obj) {
    state.goodDetailInfo = obj
  }
}

const getters = {
  categoryView(state) {
    return state.goodDetailInfo.categoryView || {}
  },
  skuInfo(state) {
    return state.goodDetailInfo.skuInfo || {}
  },
  spuSaleAttrList(state) {
    return state.goodDetailInfo.spuSaleAttrList || []
  },
  price(state) {
    return state.goodDetailInfo.price
  }
}

export default {
  namespaced: true,//开启命名空间
  state,
  actions,
  mutations,
  getters
}
